package com.xishu.service;

import com.xishu.entity.plat.GlobalSetting;
import com.xishu.util.Tools;

import java.util.List;

public class GlobalService implements Tools {
    private static GlobalService instance = new GlobalService();

    public static Object GLOBAL_LOCK = new Object();

    private GlobalService() {
    }

    public static GlobalService getInstance() {
        return instance;
    }

    /**
     * 获取全局配置
     *
     * @return
     */
    public GlobalSetting getGlobalSetting() throws Exception {
        CommonService commonService = CommonService.getInstance();
        List<GlobalSetting> globalSettingList = commonService.searchAll(GlobalSetting.class);
        if (isEmpty(globalSettingList)) {
            GlobalSetting globalSetting = new GlobalSetting();
            commonService.createObject(globalSetting);
            commonService.dealDefaultValueWithAnnotation(globalSetting);
            return globalSetting;
        } else {
            return globalSettingList.get(0);
        }
    }
}
